<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  activity_model.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-17.
//  Copyright 2011 lishuzu. All rights reserved.
// 
class Collection_model extends CI_Model
{
		function __construct(){
			parent::__construct();
			$this->userinfo = $this->session->userdata('userinfo');
		}

		function get_Collection_by_aid($aid){
			$collection = array();
			$this->db->where('aid', $aid);
			$this->db->where('uid', $this->userinfo['uid']);
			$query = $this->db->get('collection');
			foreach ($query->result_array() as $row) {
				$collection[] = $row;
			}
			return $collection;
		}
				
		function get_Collection_by_uid($uid){
			$this->db->where('uid', $uid);
			$query = $this->db->get('collection');
			foreach ($query->result_array() as $row) {
				$collection[] = $row;
			}
			return $collection;
		}
		
		function insert_collection($collection){
			if ($collection) {
				$this->db->insert('collection', $collection);
				return $this->db->insert_id();
			}else{
				return false;
			}
		}
		function delete_collection($aid){
			if ($aid && $this->userinfo['uid']) {
				$this->db->where('uid', $this->userinfo['uid']);
				$this->db->where('aid', $aid);
				$this->db->delete('collection');
				return $this->db->affected_rows();
			}else{
				return false;
			}
		}
}
?>